import request from "@/utils/request";
import type { ApiResponse } from "@/types";

// 评论创建请求
export interface CommentCreateRequest {
  postId: number;
  content: string;
  parentId?: number; // 父评论ID，用于回复
}

// 获取帖子的评论列表
export function getPostComments(postId: number, page = 1, size = 10) {
  return request({
    url: `/comments/post/${postId}`,
    method: "get",
    params: { page, size },
  });
}

// 创建评论
export function createComment(data: CommentCreateRequest) {
  return request({
    url: "/comments",
    method: "post",
    data,
  });
}

// 删除评论
export function deleteComment(commentId: number): Promise<ApiResponse> {
  return request({
    url: `/comments/${commentId}`,
    method: "delete",
  });
}

// 点赞评论
export function likeComment(commentId: number) {
  return request({
    url: `/comments/${commentId}/like`,
    method: "post",
  });
}

// 取消点赞评论
export function unlikeComment(commentId: number) {
  return request({
    url: `/comments/${commentId}/like`,
    method: "delete",
  });
}

// 获取评论详情
export function getCommentById(commentId: number) {
  return request({
    url: `/comments/${commentId}`,
    method: "get",
  });
}

// 获取评论的回复列表
export function getCommentReplies(commentId: number, page = 1, size = 10) {
  return request({
    url: `/comments/${commentId}/replies`,
    method: "get",
    params: { page, size },
  });
}
